package zero.tech.games.mj.event;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.LogicEventType;
import zero.tech.games.mj.data.MjConfig;
import zero.tech.games.mj.data.MjGameBase;
import zero.tech.games.mj.data.MjRoomCache;
import zero.tech.games.mj.data.MjTimer;

/**
 * 房间创建初始数据
 * @author ludry
 *
 */
public class RoomCreated implements EventListener{

	@Override
	public EventType netEventType() {
		return LogicEventType.ROOM_CREATED;
	}

	@Override
	public void notifyEvent(Object... objs) {
		Room room = (Room) objs[0];
		MjTimer mjTimer=new MjTimer(room.getRoom_id());
		room.setTimer(mjTimer);
		MjRoomCache mjRoomCache=new MjRoomCache(room.getRoom_id());
		room.setRoomCache(mjRoomCache);
		MjConfig mjConfig=JSONObject.parseObject(room.getConfigStr(),MjConfig.class);
		room.setGameConfig(mjConfig);
		MjGameBase mjGameBase=new MjGameBase(room);
		room.setGameBase(mjGameBase);
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
